package com.store.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.GuideShoppingNewBean;

import java.util.List;

public class GuideShoppingNewAdapter extends BaseAdapter {
    private List<GuideShoppingNewBean> guideShoppingNewBeanList;
    private Context context;
    private OnClickOrder onClickOrder;

    public interface OnClickOrder {
        void argeeClick(GuideShoppingNewBean bean);//批准
        void refuseClick(GuideShoppingNewBean bean);//拒绝
        void deleteClick(GuideShoppingNewBean bean);//删除
    }

    public GuideShoppingNewAdapter(List<GuideShoppingNewBean> guideShoppingNewBeanList, Context context, OnClickOrder onClickOrder) {
        this.guideShoppingNewBeanList = guideShoppingNewBeanList;
        this.context = context;
        this.onClickOrder = onClickOrder;
    }

    @Override
    public int getCount() {
        return guideShoppingNewBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return guideShoppingNewBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final GuideShoppingNewBean guideShoppingNewBean = guideShoppingNewBeanList.get(position);
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_new_submit, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
            holder.tv_location = (TextView) convertView.findViewById(R.id.tv_location);
            holder.tv_argee = (TextView) convertView.findViewById(R.id.tv_argee);
            holder.tv_refuse = (TextView) convertView.findViewById(R.id.tv_refuse);
            holder.tv_delete = (TextView) convertView.findViewById(R.id.tv_delete);
            holder.ll_applied = (LinearLayout) convertView.findViewById(R.id.ll_applied);
            holder.ll_delete = (LinearLayout) convertView.findViewById(R.id.ll_delete);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(TextUtils.isEmpty(guideShoppingNewBean.getNick_name())){
            holder.tv_name.setText("匿名");
        }else{
            holder.tv_name.setText(guideShoppingNewBean.getNick_name());
        }
        holder.tv_phone.setText(guideShoppingNewBean.getMobile());
        holder.tv_location.setText(guideShoppingNewBean.getAddress());
        holder.tv_argee.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickOrder.argeeClick(guideShoppingNewBean);
            }
        });
        holder.tv_refuse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickOrder.refuseClick(guideShoppingNewBean);
            }
        });
        //申请状态
        if(guideShoppingNewBean.getStatus().equals("applied")){
            holder.ll_applied.setVisibility(View.VISIBLE);
            holder.ll_delete.setVisibility(View.GONE);
        }
        //批准状态
        else if(guideShoppingNewBean.getStatus().equals("approved")){
            holder.ll_applied.setVisibility(View.GONE);
            holder.ll_delete.setVisibility(View.VISIBLE);
        }else{
            holder.ll_applied.setVisibility(View.GONE);
            holder.ll_delete.setVisibility(View.GONE);
        }
        holder.tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickOrder.deleteClick(guideShoppingNewBean);
            }
        });

        return convertView;
    }
    public  class ViewHolder {
        public TextView tv_name;               //联系人
        public TextView tv_phone;              //联系人电话
        public TextView tv_location;           //联系人地址
        public TextView tv_argee;              //批准
        public TextView tv_refuse;             //拒绝
        public LinearLayout ll_applied;         //申请
        public LinearLayout ll_delete;         //删除
        public TextView tv_delete;//删除
    }
}
